﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace OP10.ViewModels
{
    public class LifeControlViewModel : BaseViewModel
    {
        public LifeControlViewModel(IRegionManager regionManager) : base(regionManager)
        {
            InitParam();


            //开启定时器任务
            DispatcherTimer dispatcherTimer = new DispatcherTimer();
            dispatcherTimer.Interval = TimeSpan.FromMilliseconds(200);
            dispatcherTimer.Tick += OnTick;
            dispatcherTimer.Start();
        }
        private void InitParam()
        {
            BodyWeldNeedle = UseCount_Global.BodyWeldNeedle;
            PinWeldNeedle = UseCount_Global.PinWeldNeedle;
            ResistNeedle_L = UseCount_Global.ResistNeedle_L;
            ResistNeedle_R = UseCount_Global.ResistNeedle_R;

        }
        private void OnTick(object? sender, EventArgs e)
        {
            BodyWeldNeedleCurrent= WirePLCToPC_Global.USageCount_L;
            PinWeldNeedleCurrent = WirePLCToPC_Global.USageCount_R;
            LeftUseCountCurrent = TestMachinePLCToPC_Global.USageCount_L;
            RightUseCountCurrent=TestMachinePLCToPC_Global.USageCount_R;
        }
        private DelegateCommand<string> _TextChangeCommand;
        public DelegateCommand<string> TextChangeCommand =>
            _TextChangeCommand ?? (_TextChangeCommand = new DelegateCommand<string>(ExecuteTextChangeCommand));

        void ExecuteTextChangeCommand(string p)
        {
            switch (p)
            {
                case "BodyWeldNeedle":
                    UseCount_Global.BodyWeldNeedle = BodyWeldNeedle;
                    break;
                case "PinWeldNeedle":
                    UseCount_Global.PinWeldNeedle = PinWeldNeedle;
                    break;

                case "ResistNeedle_L":
                    UseCount_Global.ResistNeedle_L = ResistNeedle_L;
                    break;

                case "ResistNeedle_R":
                    UseCount_Global.ResistNeedle_R = ResistNeedle_R;
                    break;
                default:
                    break;
            }
        }

        private DelegateCommand _ResetZero01DownCmd;
        public DelegateCommand ResetZero01DownCmd =>
            _ResetZero01DownCmd ?? (_ResetZero01DownCmd = new DelegateCommand(ExecuteResetZero01DownCmd));

        void ExecuteResetZero01DownCmd()
        {
            WirePCToPLC_Global.bNeedleChangeBT = true;
        }

        private DelegateCommand _ResetZero01UpCmd;
        public DelegateCommand ResetZero01UpCmd =>
            _ResetZero01UpCmd ?? (_ResetZero01UpCmd = new DelegateCommand(ExecuteResetZero01UpCmd));

        void ExecuteResetZero01UpCmd()
        {
            WirePCToPLC_Global.bNeedleChangeBT = false;

        }


        private DelegateCommand _ResetZero02DownCmd;
        public DelegateCommand ResetZero02DownCmd =>
            _ResetZero02DownCmd ?? (_ResetZero02DownCmd = new DelegateCommand(ExecuteResetZero02DownCmd));

        void ExecuteResetZero02DownCmd()
        {

            TestMachinePCToPLC_Global.bNeedleChangeBT=true;
        }

        private DelegateCommand _ResetZero02UpCmd;
        public DelegateCommand ResetZero02UpCmd =>
            _ResetZero02UpCmd ?? (_ResetZero02UpCmd = new DelegateCommand(ExecuteResetZero02UpCmd));

        void ExecuteResetZero02UpCmd()
        {
            TestMachinePCToPLC_Global.bNeedleChangeBT = false;
        }

        #region 属性
        private int _BodyWeldNeedle;
        public int BodyWeldNeedle
        {
            get { return _BodyWeldNeedle; }
            set { SetProperty(ref _BodyWeldNeedle, value); }
        }

        private int _PinWeldNeedle;
        public int PinWeldNeedle
        {
            get { return _PinWeldNeedle; }
            set { SetProperty(ref _PinWeldNeedle, value); }
        }
        private int _ResistNeedle_L;
        public int ResistNeedle_L
        {
            get { return _ResistNeedle_L; }
            set { SetProperty(ref _ResistNeedle_L, value); }
        }

        private int _ResistNeedle_R;
        public int ResistNeedle_R
        {
            get { return _ResistNeedle_R; }
            set { SetProperty(ref _ResistNeedle_R, value); }
        }


        private int _BodyWeldNeedleCurrent;
        public int BodyWeldNeedleCurrent
        {
            get { return _BodyWeldNeedleCurrent; }
            set { SetProperty(ref _BodyWeldNeedleCurrent, value); }
        }

        private int _PinWeldNeedleCurrent;
        public int PinWeldNeedleCurrent
        {
            get { return _PinWeldNeedleCurrent; }
            set { SetProperty(ref _PinWeldNeedleCurrent, value); }
        }
        private int _LeftUseCountCurrent;
        public int LeftUseCountCurrent
        {
            get { return _LeftUseCountCurrent; }
            set { SetProperty(ref _LeftUseCountCurrent, value); }
        }

        private int _RightUseCountCurrent;
        public int RightUseCountCurrent
        {
            get { return _RightUseCountCurrent; }
            set { SetProperty(ref _RightUseCountCurrent, value); }
        }

        #endregion
    }
}
